<?php
include("config.php");

if(empty($_POST['token'])){
	echo json_res(true,'paramError','提交数据不全!');
	return;
}

//////////////////////////////////////////////////////////////////////////////////////
//获取姓名学号等
$snoopy1 = new Snoopy;
//模拟HEADER
$snoopy1->cookies['ASP.NET_SessionId'] = $_SESSION["ASP_NET_SessionId"];
//获取分析表单
$snoopy1->fetch($personurl);
$res1 = $snoopy1->results;

//超时返回
if ($snoopy1->status != '200' || $snoopy1->timed_out) {
	echo json_res(true,'systemTimeOut',"页面获取超时！");
	return;
}
$snoopy_results = $snoopy1->results;

if(stripos($snoopy_results,"action=\"login.aspx\"")){
	echo json_res(true,'tokenTimeOut',"token失效");
	return;
}

$res1_html = new simple_html_dom();
$res1_html->load($res1);
$res1_tds  = $res1_html->find('td');
$info_data = [];
$info_title= [];
foreach ($res1_tds as $key => $value){
	$innertext = trim(strip_tags($value->innertext));
	if($key == 0 || ($key>4 && $key%2==1)){
		$info_title[] = $innertext;
	}
	if($key == 1 || ($key>4 && $key%2==0)){
		$info_data[] = $innertext;
	}
}

$res1_html->clear();

file_put_contents("_info/".$_SESSION["userID"], $snoopy_results);
//////////////////////////////////////////////////////////////////////////////////////
//获取照片
$snoopy2 = new Snoopy;
//模拟HEADER
$snoopy2->cookies['ASP.NET_SessionId'] = $_SESSION["ASP_NET_SessionId"];
//获取分析表单
$snoopy2->fetch($photourl);
$res2 = $snoopy2->results;

//超时返回
if ($snoopy2->status != '200' || $snoopy2->timed_out) {
	echo json_res(true,'systemTimeOut',"页面获取超时！");
	return;
}
$pic_data = "data:image/gif;base64,".base64_encode($snoopy2->results);
file_put_contents("_photo/".$_SESSION["userID"].".gif", $snoopy2->results);

$info_title[] = "照片";
$info_data[]  = $pic_data;
$info = ["title"=>$info_title,"data"=>$info_data];
//////////////////////////////////////////////////////////////////////////////////////

//处理成更易用的数据
$xh = $info_data[0];
$yx = $info_data[59];
$yx_arr = explode("_", $yx);
$xy = $yx_arr[0];
$zy = $yx_arr[1];
$bj = $zy.substr($xh,1,2)."研";

$intro["title"] = array(
	"学号","姓名","性别","学院","专业","班级","导师","生日",
	"身份证号","民族","政治面貌","毕业院校","家庭住址","照片"
	);
$intro["data"] = array(
	'xh'  => $xh, //学号
	'xm'  => $info_data[1], //姓名
	'xb'  => $info_data[3], //性别
	'xy'  => $xy, //学院
	'zy'  => $zy, //专业
	'bj'  => $bj, //班级
	'ds'  => $info_data[63], //导师
	'sr'  => $info_data[4], //生日
	'sfzh'=> $info_data[6], //身份证号
	'mz'  => $info_data[8], //民族
	'zzmm'=> $info_data[9], //政治面貌
	'byyx'=> $info_data[19], //毕业院校
	'jtzz'=> $info_data[18], //家庭住址
	'zp'  => $pic_data, //照片
);
//noapi调用
if(!empty($_POST['noapi'])){
	echo json_res(false,$info);
	return;
}

if($path == "info")
	echo json_res(false,$info);
else{
	echo json_res(false,$intro);
}
return;
